<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="项目信息">
          <el-input style="width:180px" v-model="queryParam.qry_project" placeholder="项目名称关键词或编号" @keyup.enter.native="doQuery"></el-input>
        </el-form-item>
        <el-form-item label="项目级别">
          <el-select v-model="projectlevel" multiple clearable placeholder="请选择项目级别" style="width:190px" @change="doQueryConcatProjectLevel">
            <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label-width="0">
        <el-switch
          v-model="finishproject"
          active-text="全部"
          active-value="1"
          inactive-text="进行中"
          inactive-value="0" @change="doQuery">
        </el-switch>
        </el-form-item>
      </template>
      <template slot="button">
        <el-button type="primary" icon="el-icon-zoom-in" @click="openDeatailSearchDialog">详细查询</el-button>
      </template>
      <template slot="button">
        <el-button type="primary" icon="el-icon-delete" @click="resetQuery">重置</el-button>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" :refMainTable="$refs.mainTable" currentModuleTableCode="gpmProject/query" :startColumn="3" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0" :isDisplayDeleteBatch="false" :isDisplayAdd="false">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :row-style="tableRowStyle" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <!-- <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column> -->
        <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
        <el-table-column prop="whetherhistorydata" label="是否补录" width="100px" sortable="custom" sort-by="whetherhistorydata" align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <template v-if="scope.row.whetherhistorydata === '1'">是</template>
            <template v-else>否</template>
          </template>
        </el-table-column>
        <el-table-column prop="dispdeptcommoncode1" label="所属部门" width="150px" sortable="custom" sort-by="applydeptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectnumber" label="项目编号" width="230px" sortable="custom" sort-by="projectnumber" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectname" label="项目名称" width="150px" sortable="custom" sort-by="projectname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectlevel" label="项目级别" width="80px" sortable="custom" sort-by="projectlevel" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmanager" label="项目经理" width="80px" sortable="custom" sort-by="projectmanager" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectstate" label="项目阶段" width="115px" sortable="custom" sort-by="projectstate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="target" label="项目目标" width="150px" sortable="custom" sort-by="target" align="center" header-align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
              <el-row v-for="(item, index) in scope.row.dispproductline" :key="index">
                <el-tag v-if="item.dispproductline !== null && item.dispproductline !== undefined && item.dispproductline !== ''">{{ item.dispproductline }}</el-tag>
              </el-row>
          </template>
        </el-table-column>
        <el-table-column prop="dispprojectstate" label="项目状态" width="150px" sortable="custom" sort-by="projectstate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="daynum" label="超期时间" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="superviselist" width="200px" label="督办情况" align="left" header-align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <div v-if="scope.row.superviselist !== '' && scope.row.superviselist !== undefined">
              <el-row v-for="(item, index) in scope.row.superviselist" :key="index">
                <div class="superviser" @click="openViewDialog('superviseeditForm', item.id)">
                  <span>{{ item.supervisecode }}</span>
                  <el-button class="superviserButton" :type="supervisecolor(item.dispsupervisestate)" size="mini" plain>{{ item.dispsupervisestate }}</el-button>
                </div>
              </el-row>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="bidcycle" label="项目周期" width="80px" sortable="custom" sort-by="bidcycle" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planstartdate" label="计划开始日期" width="105px" sortable="custom" sort-by="planstartdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planenddate" label="计划结束日期" width="105px" sortable="custom" sort-by="planenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="actualenddate" label="实际结束日期" width="170px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="contractenddates" label="合同结束日期" width="105px" align="center" header-align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-row v-for="(item, index) in scope.row.contractenddates" :key="index">
              <el-tag v-if="item.contractenddate !== null && item.contractenddate !== undefined && item.contractenddate !== ''">{{ item.contractenddate | toDateTime('yyyy-MM-dd') }}</el-tag>
            </el-row>
          </template>
        </el-table-column>
        <el-table-column prop="agreeddeliverydates" label="合同约定交付日期" width="150px" align="center" header-align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-row v-for="(item, index) in scope.row.agreeddeliverydates" :key="index">
              <el-tag v-if="item.agreeddeliverydate !== null && item.agreeddeliverydate !== undefined && item.agreeddeliverydate !== ''">{{ item.agreeddeliverydate | toDateTime('yyyy-MM-dd') }}</el-tag>
            </el-row>
          </template>
        </el-table-column>
        <el-table-column prop="sponsor" label="Sponsor" width="80px" sortable="custom" sort-by="sponsor" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="owner" label="Owner" width="80px" sortable="custom" sort-by="owner" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="decisionusername" label="决策组成员" width="150px" sortable="custom" sort-by="decisionusername" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="background" label="项目背景概述" width="150px" sortable="custom" sort-by="background" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="submitbegindate" label="立项开始时间" width="105px" sortable="custom" sort-by="planstartdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="submitfinishdate" label="立项结束时间" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="appointbegindate" label="任命开始时间" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="appointfinishdate" label="任命结束时间" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planbegindate" label="策划开始时间" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planfinishdate" label="策划结束时间" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="reviewbegindate" label="复盘开始时间" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="reviewfinishdate" label="复盘结束时间" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item type="text" icon="el-icon-edit" :disabled="(!scope.row.changeownerpermission || scope.row.projectstate === '0')" @click.native="openChangeOwnerDialog('changeOwnerForm', scope.row)">变更项目经理</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" type="flex" ref="pager" align="bottom">
        <el-col :span="12" style="margin-bottom:5px;">
          <el-col style="background-color:#D80A1E;height: 20px;width:20px;margin-left:10px" :offset="0"> </el-col>
          <el-col class="projectStateContext" :offset="0">
            项目超期
          </el-col>
          <el-col style="background-color:#FF8C2E;height: 20px;width:20px" :offset="0"> </el-col>
          <el-col class="projectStateContext" :offset="0">
            里程碑超期
          </el-col>
          <el-col style="background-color:#0000FF;height: 20px;width:20px" :offset="0"> </el-col>
          <el-col class="projectStateContext" :offset="0">
            流程超期
          </el-col>
          <el-col style="background-color:#B8860B;height: 20px;width:20px" :offset="0"> </el-col>
          <el-col class="projectStateContext" :offset="0">
            任务超期
          </el-col>
        </el-col>
        <el-col :span="12">
          <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
        </el-col>
      </el-row>
      <index-comp ref="indexComp" :projectcode="projectcode" :fromIndexType="'query'"></index-comp>
      <change-owner ref="changeOwnerForm"></change-owner>
      <tl-supervise-edit ref="superviseeditForm" @refresh="doRefresh"></tl-supervise-edit>
      <tl-detail-search ref="detailSearch" @resetQueryParam="resetQueryForDetailSearch" :codeModel="codeModel" :queryParams.sync="queryParam" :createDepart.sync="createdepart" :projectLevel.sync="projectlevel" @loadData="loadData" :doDisplayState="true"></tl-detail-search>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { filterObjectNull } from '@tapui/utils/util'
import { validateNull } from '@tapui/utils/validate'
/** 子组件 */
import indexComp from '../gpmProjectInfo/indexForQueryComp'
import tlSuperviseEdit from '@/views/gpm/gpmProjectSupervise/editView'
import tlDetailSearch from './component/DetailSearch'
import changeOwner from "./component/changeOwner"
/** 工具类 */
import { checkPermission } from '@tapui/utils/permission'
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'sdProjectQuery',
  mixins: [mixin_list],
  components: { indexComp, tlDetailSearch, tlSuperviseEdit, changeOwner },
  data() {
    return {
      description: 'SD项目监管',
      urlPrefix: '/sd/project/',
      url: {
        queryCodeList: '/sd/project/dataCodeList',
        list: '/sd/project/listForQuery'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'abnormalstate desc,id ',
        sord: 'desc'
      },
      projectcode: '',
      projectlevel: [],
      createdepart: [],
      // 路由跳转获取项目等级
      projectLevelListRouter: [],
      finishproject: '0'
    }
  },
  methods: {
    openChangeOwnerDialog(editForm, item) {
      this.$refs[editForm].id = item.id
      this.$refs[editForm].isAdd = false
      this.$refs[editForm].visible = true
      this.$refs[editForm].disableEditSubmit = false
      this.$refs[editForm].model = item
      let that = this
      setTimeout(() => {
        that.clickRowkey = item.id
      }, 100)
    },
    // 督办状态配置
    supervisecolor(e) {
      if (e === '超期') {
        return 'warning'
      } else if (e === '已完成') {
        return 'success'
      } else if (e === '进行中') {
        return 'primary'
      }
    },
    // 部门名称多选框
    doQueryConcatCreateDepart(data) {
      if (data.length > 0) {
        this.queryParam.qry_createdepart = data
          .map((item) => {
            return "'" + item + "'"
          })
          .join(',')
      } else {
        this.queryParam.qry_createdepart = null
      }
    },
    // 项目级别多选框
    doQueryConcatProjectLevel(data) {
      if (data.length > 0) {
        this.queryParam.qry_projectlevel = data
          .map((item) => {
            return "'" + item + "'"
          })
          .join(',')
      } else {
        this.queryParam.qry_projectlevel = null
      }
    },
    // 重置查询条件(子组件调用)
    resetQueryForDetailSearch() {
      this.queryParam = {}
      this.param = {}
      this.projectlevel = []
      this.createdepart = []
      this.doQuery()
    },
    // 重置所有参数
    resetQuery() {
      this.queryParam = {}
      this.param = {}
      this.projectlevel = []
      this.createdepart = []
      this.$refs.detailSearch.resetQueryParam()
      this.doQuery()
    },
    // 打开详细查询页面
    openDeatailSearchDialog() {
      this.$refs.detailSearch.visible = true
    },
    tableRowStyle(row, index) {
      if (row.row.abnormalstate === 30) {
        return { 'background-color': 'rgb(235,75,75)', color: 'white' }
      } else if (row.row.abnormalstate === 20) {
        return { 'background-color': 'rgb(255,140,46)', color: 'white' }
      } else if (row.row.abnormalstate === 10) {
        return { 'background-color': 'rgb(184,134,11)', color: 'white' }
      } else if (row.row.abnormalstate === 15) {
        return { 'background-color': '#0000FF', color: 'white' }
      }
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    doRowDbClick(row, column, event) {
      this.projectcode = row.projectcode
      this.$nextTick(() => {
        this.$refs.indexComp.id = row.id
        this.$refs.indexComp.visible = true
      })
    },
    /** 改变审核状态标签颜色 */
    changeStateType(state) {
      return state === 0 ? 'info' : state === 2 ? 'danger' : state === 9 ? 'success' : ''
    },
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      // 路由跳转，获取项目等级信息
      if (this.$route.query.level !== undefined && this.$route.query.level !== null) {
        param.qry_projectlevel = this.$route.query.level
        this.$route.query.level = null
      }
      // 路由跳转，获取项目异常状态信息
      if (this.$route.query.abnormalstate !== undefined && this.$route.query.abnormalstate !== null) {
        param.qry_abnormalstate = this.$route.query.abnormalstate
        this.$route.query.abnormalstate = null
      }
      // 路由跳转，获取项目状态信息
      if (this.$route.query.projectstate !== undefined && this.$route.query.projectstate !== null) {
        param.qry_projectstate = this.$route.query.projectstate
        this.$route.query.projectstate = null
      }
      // 路由跳转，获取项目权限信息
      if (this.$route.query.dataPermission !== undefined && this.$route.query.dataPermission !== null) {
        this.queryParam.qry_dataPermission = this.$route.query.dataPermission
      }
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      Object.assign(param, this.queryParam, this.sorterInfo, this.filtersInfo)
      param.qry_finishproject = this.finishproject
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      return filterObjectNull(param)
    }
  }
}
</script>

<style scoped>
.app-container >>> .el-table tbody tr:hover > td {
  background-color: transparent !important;
}
.app-container {
  height: 100%;
  padding: 10px;
  margin: 12px;
  background: white;
  border-radius: 5px;
}
.superviser {
  display: flex;
}
.superviserButton {
  margin-left: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 50px;
  height: 22px;
}
</style>
